﻿using MediatR;
using ERPSystem.Common.DTO;
using ERPSystem.Common.Infrastructure.IRepository;
using ERPSystem.Common.Domains.CustomerProfileCommon;

namespace BasicInformationCommon.API.BasicInformationCommons.DropDownCommon.ClientTypeRead
{
    public class ClientTypeQueryHandler : IRequestHandler<ClientTypeQueryCommand, Result>
    {
        private readonly IBaseRepository<ClientType> _clientTypeRepository;

        public ClientTypeQueryHandler(IBaseRepository<ClientType> clientTypeRepository)
        {
            _clientTypeRepository = clientTypeRepository;
        }
        /// <summary>
        /// 查询客户分类业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(ClientTypeQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            try
            {
                var clientTypeList = await (await _clientTypeRepository.GetAll()).ToListAsync();
                result.Data = clientTypeList;
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
